/*
* pps-cloud
*/
package com.pitop.payment.ctrl;


import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

import com.pitop.core.exceptions.BaseException;
import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.payment.entity.PaymentTerm;
import com.pitop.payment.service.PaymentTermSVImpl;

/**
 * 支付方式 控制器
 *
 * @author berton
 */
@RestController
@RequestMapping("/paymentTerm")
@Slf4j
@Api(value = "支付方式控制器", description = "支付方式控制器")
public class PaymentTermCtrl {

    @Resource
    protected RedisUtils redisUtils;
    @Autowired
    private PaymentTermSVImpl paymentTermSVImpl;


    /**
    * 查询PaymentTerm一个详情信息
    * @param id 
    * @param code 编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询PaymentTerm一个详情信息", notes = "查询PaymentTerm一个详情信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "编码",dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(java.lang.Long id,java.lang.String code) {
        if(id==null){
          return null;
        }
        if(code==null){
          return null;
        }
        PaymentTerm paymentTerm = paymentTermSVImpl.load(id,code);
        log.info(JSON.toJSONString(paymentTerm));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, paymentTerm);
    }


    /**
    * 根据条件id查询PaymentTerm一个详情信息
    *
    * @param id 
    * @return BeanRet
    */
    @ApiOperation(value = "查询PaymentTerm一个详情信息", notes = "查询PaymentTerm一个详情信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable java.lang.Long id) {
        if(id==null||id==0){
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        PaymentTerm paymentTerm = paymentTermSVImpl.loadById(id);
        log.info(JSON.toJSONString(paymentTerm));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, paymentTerm);
    }
    /**
    * 根据条件code查询PaymentTerm一个详情信息
    *
    * @param code 编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询PaymentTerm一个详情信息", notes = "查询PaymentTerm一个详情信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "code", value = "编码",dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public BeanRet loadByCode(@PathVariable java.lang.String code) {
        if(StringUtils.isEmpty(code)){
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        PaymentTerm paymentTerm = paymentTermSVImpl.loadByCode(code);
        log.info(JSON.toJSONString(paymentTerm));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, paymentTerm);
    }


    /**
    * 查询PaymentTerm信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询PaymentTerm信息集合", notes = "查询PaymentTerm信息集合")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
        @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),

    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(@ApiIgnore PaymentTerm paymentTerm,@ApiIgnore Page<PaymentTerm> page) {
        if(page==null){
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        List<PaymentTerm> paymentTerms = paymentTermSVImpl.list(paymentTerm,page.getCurPage(),page.getPageSize());
        int total = paymentTermSVImpl.count(paymentTerm);
        page.setTotalRow(total);
        page.setVoList(paymentTerms);
        log.info(JSON.toJSONString(page));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, "", page);
    }


    /**
    * 查询PaymentTerm信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询PaymentTerm信息集合", notes = "查询PaymentTerm信息集合")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
        @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(java.lang.Long id,java.lang.String code,@ApiIgnore Page<PaymentTerm> page) {
        if(page==null){
           return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        List<PaymentTerm> paymentTerms = paymentTermSVImpl.list(id,code, page.getCurPage(),page.getPageSize());
        int total = paymentTermSVImpl.count(id,code);
        page.setTotalRow(total);
        page.setVoList(paymentTerms);
        log.info(JSON.toJSONString(page));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, "", page);
    }

    /**
    * 创建PaymentTerm
    *
    * @return BeanRet
    */
    @ApiOperation(value = "创建PaymentTerm", notes = "创建PaymentTerm")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
        @ApiImplicitParam(name = "payment", value = "支付方式", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore PaymentTerm paymentTerm) {
        if (StringUtils.isEmpty(paymentTerm.getCode())) {
           return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(paymentTerm.getPayment())) {
           return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        paymentTermSVImpl.save(paymentTerm);
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success,paymentTerm);
    }


    /**
    * 修改PaymentTerm
    *
    * @return BeanRet
    */
    @ApiOperation(value = "修改PaymentTerm", notes = "修改PaymentTerm")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
        @ApiImplicitParam(name = "payment", value = "支付方式", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore PaymentTerm paymentTerm) {
        if (StringUtils.isEmpty(paymentTerm.getCode())) {
         return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(paymentTerm.getPayment())) {
         return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        paymentTermSVImpl.modify(paymentTerm);
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success,paymentTerm);
    }

    /**
    * 根据主键删除PaymentTerm
    *
    * @return BeanRet
    */
    @ApiOperation(value = "删除PaymentTerm", notes = "删除PaymentTerm")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id,java.lang.String code) {
        if (id!=null&&StringUtils.isEmpty(code)) {
           return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }

        paymentTermSVImpl.delete(id,code);
        return BeanRet.create(true, "删除PaymentTerm成功");
    }


}
